package com.itheima.app.controller;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.app.manager.SettingsManager;
import com.itheima.domain.db.Notification;
import com.itheima.domain.db.User;
import com.itheima.domain.db.UserInfo;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.domain.vo.SettingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

@RestController
public class SettingsController {

    @Autowired
    private SettingsManager settingsManager;

    //查询用户的通知信息
    @GetMapping("/users/settings")
    public SettingVo findMySettings() throws IOException {
        User user = UserHolder.get();
        return  settingsManager.findMySettings(user);
    }


    //保存或者更新陌生人问题
    @PostMapping("/users/questions")
    public Map saveOrUpdateQuestions(@RequestBody Map<String , String> map){
        String content = map.get("content");
        //保存或更新
        settingsManager.saveOrUpdateQuestions(content);
        return null;
    }
    //保存或者更新通知
    @PostMapping("/users/notifications/setting")
    public Map saveOrUpdateNotifications(@RequestBody Notification notification){

        //保存或更新
        settingsManager.saveOrUpdateNotifications(notification);
        //return ResponseEntity.ok(数据); 多一个可控的状态码
        //return ResponseEntity.status(500).body("xxx报错了");
        return null;
    }


    //黑名单用户查询
    @GetMapping("/users/blacklist")
    public PageBeanVo findBlackList(
            @RequestParam(defaultValue = "1" , name = "page") Integer pageNumber ,
            @RequestParam(defaultValue = "10", name = "pageSize" )Integer pageSize){
        return  settingsManager.findBlackList(pageNumber , pageSize);
    }

    //黑名单用户查询 rest风格
    ///users/blacklist/变量
    @DeleteMapping("/users/blacklist/{blackUserId}")
    public Map deleteBlackUser(@PathVariable Long blackUserId){
        return  settingsManager.deleteBlackUser(blackUserId);
    }
}
